/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package be.ac.ua.pats.thesisrobotica.robot.actuators;

import be.ac.ua.pats.thesisrobotica.robot.communication.Connection;
import be.ac.ua.pats.thesisrobotica.robot.sensors.IdFactory;
import be.ac.ua.pats.thesisrobotica.robot.sensors.Sensor;
import lejos.nxt.MotorPort;

/**
 *
 * @author Admin
 */
public class Motor extends Sensor {

    lejos.nxt.Motor sensor;

    public Motor(MotorPort port) {
        this(null,port);
    }

    public Motor(Connection connection, MotorPort port) {
        super(connection);
        sensor = new lejos.nxt.Motor(port);
        this.connection = connection;
        this.id = IdFactory.generate();
    }


    public String getValue() {

        if(sensor.isForward()) {
            return "1";
        } else if(sensor.isBackward()) {
            return "-1";
        } else {
            return "0";
        }

        
    }

    public void setValue(String s) {
        switch(Integer.parseInt(s)) {
            case(1):
                sensor.forward();
                break;
            case(0):
                sensor.stop();
                break;
            case(-1):
                sensor.backward();
                break;
        }
    }
}
